home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
-
- File: sfx lists.c
-
- Purpose: This module handles anything and everything about lists:
- initializing, drawing, scrolling, clicking, etc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program in a file named "GNU General Public License".
- If not, write to the Free Software Foundation, 675 Mass Ave,
- Cambridge, MA 02139, USA.
-
- \**********************************************************************/
-
- #include "sfx lists.h"
- #include "sfx meat.h"
- #include "error.h"
-
- #define kTextLDEF 0 /* default LDEF */
- #define kDoDraw TRUE /* always draw list after changes */
- #define kNoGrow FALSE /* don't leave room for size box */
- #define kIncludeScroll TRUE /* leave room for scroll bar */
- #define kScrollWidth 15 /* width of scroll bar */
-
- ListHandle MyCreateVerticalScrollingList(WindowPtr theWindow, Rect boundsRect,
- short columnsInList, short theLDEF)
- {
- Rect dataBoundsRect;
- Point cellSize;
-
- SetRect(&dataBoundsRect, 0, 0, columnsInList, 0);
- SetPt(&cellSize, 0, 0);
- boundsRect.right=boundsRect.right-kScrollWidth;
- return LNew(&boundsRect, &dataBoundsRect, cellSize, theLDEF, theWindow, kDoDraw,
- kNoGrow, !kIncludeScroll, kIncludeScroll);
- }
-
- void MyDrawListBorder(ListHandle theList)
- {
- Rect theBorder;
- PenState thePenState;
-
- theBorder=(**theList).rView;
- GetPenState(&thePenState);
- PenSize(1,1);
- InsetRect(&theBorder, -1, -1);
- FrameRect(&theBorder);
- SetPenState(&thePenState);
- }
-
- void MyDrawActiveListBorder(ListHandle theList, Boolean isActive)
- {
- Rect outlineRect;
- PenState thePenState;
-
- outlineRect=(**theList).rView;
- if (((**theList).vScroll)!=0L)
- outlineRect.right+=kScrollWidth;
- if (((**theList).hScroll)!=0L)
- outlineRect.bottom+=kScrollWidth;
- SetPort((**theList).port);
- InsetRect(&outlineRect, -4, -4);
- GetPenState(&thePenState);
- if ((isActive) && ((**theList).lActive))
- PenPat(black);
- else
- PenPat(white);
- PenSize(2,2);
- FrameRect(&outlineRect);
- SetPenState(&thePenState);
- }
-
- void MyAddStr255ToList(ListHandle theList, Str255 theStr)
- {
- short rowNum;
- Cell theCell;
-
- rowNum=(**theList).dataBounds.bottom;
- rowNum=LAddRow(1, rowNum, theList);
- SetPt(&theCell, 0, rowNum);
- LSetCell(&theStr[1], theStr[0], theCell, theList);
- }
-
- void MyDeleteItemFromList(ListHandle theList, short index)
- {
- /* index is 0-based */
- LDelRow(1, index, theList);
- }
-
- void MyHandleMouseDownInList(WindowDataHandle theData, ListHandle theList,
- EventRecord *theEvent, Boolean isUsedList)
- {
- Point thePoint;
-
- thePoint=theEvent->where;
- SetPort((**theList).port);
- GlobalToLocal(&thePoint);
- if (LClick(thePoint, theEvent->modifiers, theList))
- MyHandleDoubleClickInList(theList);
- }
-
- void MyUpdateList(ListHandle theList)
- {
- SetPort((**theList).port);
- LUpdate((**theList).port->visRgn, theList);
- MyDrawListBorder(theList);
- }
-
- Boolean MyGetFirstSelectedCell(ListHandle theList, Cell *theCell)
- {
- SetPt(theCell, 0, 0);
- return LGetSelect(TRUE, theCell, theList);
- }
-
- void MySelectOneCell(ListHandle theList, Cell theCell)
- {
- LDoDraw(FALSE, theList);
- MyDeselectAllCells(theList);
- LSetSelect(TRUE, theCell, theList);
- LDoDraw(TRUE, theList);
- MyUpdateList(theList);
- }
-
- void MyMakeCellVisible(ListHandle theList, Cell theCell)
- {
- Rect visibleRect;
- short dCols, dRows;
-
- visibleRect=(**theList).visible;
- if (!PtInRect(theCell, &visibleRect))
- {
- dCols=dRows=0;
- if (theCell.h>visibleRect.right-1)
- dCols=theCell.h-visibleRect.right+1;
- else if (theCell.h<visibleRect.left)
- dCols=theCell.h-visibleRect.left;
- else if (theCell.v>visibleRect.bottom-1)
- dRows=theCell.v-visibleRect.bottom+1;
- else if (theCell.v<visibleRect.top)
- dRows=theCell.v-visibleRect.top;
- LScroll(dCols, dRows, theList);
- }
- }
-
- void MyDeselectAllCells(ListHandle theList)
- {
- Cell nextSelectedCell;
-
- if (MyGetFirstSelectedCell(theList, &nextSelectedCell))
- {
- LDoDraw(FALSE, theList);
- while (LGetSelect(TRUE, &nextSelectedCell, theList))
- {
- LSetSelect(FALSE, nextSelectedCell, theList);
- }
- LDoDraw(TRUE, theList);
- }
- }
-
- void MyClearAllCells(ListHandle theList)
- {
- LDelRow(0, 0, theList);
- }
-
- void MyGetCellData(ListHandle theList, Cell theCell, Str255 theName)
- {
- short len;
-
- len=63;
- LGetCell(&theName[1], &len, theCell, theList);
- theName[0]=len;
- }
-
- void MyHandleDoubleClickInList(ListHandle theList)
- {
- HandleError(DoTheDemoFade(theList), FALSE, FALSE);
- }
-